import { ObjectUtil } from '../utils/ObjectUtil';
export const ignoreClientError = status =>
	(status >= 200 && status < 300) || (status >= 400 && status < 500);
export const ignoreAllError = () => true;
export const reverseStatus = status => status >= 400 && status < 500;
let defaultHttpConfig = {
	id: Symbol.for('Api')
};
export const HttpConfigSource = {
	/**
	 * @author 戴俊明 <idaijunming@163.com>
	 * @description 修改默认 HTTP 配置
	 * @date 2020/3/12 17:00
	 **/
	setSource: config => {
		defaultHttpConfig = config;
	},
	/**
	 * @author 戴俊明 <idaijunming@163.com>
	 * @description 获取默认 HTTP 配置
	 * @date 2020/3/12 17:01
	 **/
	getSource: () => defaultHttpConfig,
	/**
	 * @author 戴俊明 <idaijunming@163.com>
	 * @description 将 config 与默认 HTTP 配置合并并保存
	 * @date 2020/3/12 17:01
	 **/
	upgrade: config => {
		defaultHttpConfig = ObjectUtil.assign(defaultHttpConfig, config);
	},
	/**
	 * @author 戴俊明 <idaijunming@163.com>
	 * @description 将 config 与默认 HTTP 配置合并
	 * @date 2020/3/12 17:01
	 **/
	merge: config => {
		if (config) {
			return ObjectUtil.assign(defaultHttpConfig, config);
		}
		return defaultHttpConfig;
	}
};
